/*
 * Deck.java
 *
 * Created on September 5, 2007, 8:32 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package blackjacksim;

import java.util.*;

/**
 *
 * @author Eric Drucker
 */
public class Deck
{
	ArrayList<Card> deck;
	
	/** Creates a new instance of Deck */
	public Deck()
	{
		deck = new ArrayList<Card>();
	}
	
	public Card deal()
	{
		Card c = deck.get(0);
		deck.remove(0);
		
		return c;
	}
	
	public void shuffle()
	{
		deck = new ArrayList<Card>();
		ArrayList<Card> cards = new ArrayList<Card>();
	
		Random rand = new Random();
		
		for(Card.suit s : Card.suit.values())
		{
			for(Card.value v : Card.value.values())
			{
				//set image name
				String image = "./cards/";
				
				switch (v)
				{
					case ACE:	image += "A"; break;
					case TWO:	image += "2"; break;
					case THREE:	image += "3"; break;
					case FOUR:	image += "4"; break;
					case FIVE:	image += "5"; break;
					case SIX:	image += "6"; break;
					case SEVEN:	image += "7"; break;
					case EIGHT:	image += "8"; break;
					case NINE:	image += "9"; break;
					case TEN:	image += "T"; break;
					case JACK:	image += "J"; break;
					case QUEEN:	image += "Q"; break;
					case KING:	image += "K"; break;
				}
					
				switch (s)
				{
					case CLUB:	image += "C"; break;
					case DIAMOND:	image += "D"; break;
					case HEART:	image += "H"; break;
					case SPADE:	image += "S"; break;
				}
				
				image += ".gif";
				
				Card tempCard = new Card(s, v, image);
				cards.add(tempCard);
			}
		}

		
		
		
		//pull cards randomly out of sorted deck and add them to shuffled deck
		
		for(int i = cards.size(); i >0; i--)
		{
			int index = rand.nextInt(i);
			deck.add(cards.get(index));
			cards.remove(index);
		}
		
	}
	
	
	public int numCardsLeft()
	{
		return deck.size();
	}
	
}
